<%--<%@ page import="java.sql.DriverManager" %>--%>
<%--<%@ page import="java.sql.Connection" %>--%>
<%--<%@ page import="java.sql.Statement" %>--%>
<%--<%@ page import="java.sql.ResultSet" %>--%>
<%--<%@ page import="com.gzsz.util.DBUtil" %>--%>
<%--<%@ page contentType="text/html;charset=UTF-8" language="java" %>--%>
<%--<html>--%>
<%--<head>--%>
<%--    <Title>用户表格</Title>--%>
<%--    <meta charset="UTF-8">--%>
<%--    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">--%>
<%--</head>--%>
<%--<style>--%>
<%--    body {--%>
<%--        font-family: Arial, sans-serif;--%>
<%--        background-color: #f4f4f4;--%>
<%--        margin-bottom: 20%;--%>
<%--    }--%>
<%--    a {--%>
<%--        display: inline-block;--%>
<%--        padding: 6px 12px;--%>
<%--        margin-right: 5px;--%>
<%--        text-decoration: none;--%>
<%--        border: 1px solid #ccc;--%>
<%--        border-radius: 4px;--%>
<%--        color: #333;--%>
<%--        background-color: #f9f9f9;--%>
<%--        transition: all 0.3s ease;--%>
<%--        /* 将<a>标签设置为内联块元素，设置内边距、右边距，去除默认下划线，--%>
<%--           设置边框、边框圆角、文本颜色、背景颜色，并添加过渡效果，使样式变化更平滑 */--%>
<%--    }--%>

<%--    a:hover {--%>
<%--        background-color: #adadad;--%>
<%--        border-color: #adadad;--%>
<%--        color: #000;--%>
<%--        cursor: pointer;--%>
<%--        /* 鼠标悬停在<a>标签上时，改变背景颜色、边框颜色、文本颜色，--%>
<%--           并将鼠标指针样式改为指针形状，提示用户可点击 */--%>
<%--    }--%>
<%--</style>--%>
<%--<body>--%>
<%--<div>--%>
<%--    <table class="table table-bordered table-striped table-hover">--%>
<%--        <thead>--%>
<%--        <tr>--%>
<%--            <th>编号</th>--%>
<%--            <th>患者姓名</th>--%>
<%--            <th>年龄</th>--%>
<%--            <th>性别</th>--%>
<%--            <th>出生日期</th>--%>
<%--            <th>诊断结果</th>--%>
<%--            <th>住院日期</th>--%>
<%--            <th>预计出院日期</th>--%>
<%--            <th>病房号</th>--%>
<%--            <th>病床号</th>--%>
<%--            <th>数据操作</th>--%>
<%--        </tr>--%>
<%--        </thead>--%>
<%--        <tbody>--%>
<%--        <%--%>
<%--            DBUtil dbUtil=new DBUtil();--%>
<%--            //    1：加载驱动（加载我们代码里面）--%>
<%--//            Class.forName("com.mysql.cj.jdbc.Driver");--%>
<%--////    2：创建连接--%>
<%--//            String url = "jdbc:mysql://localhost:3306/medicald?serverTimezone=Asia/Shanghai";--%>
<%--//            String user = "root";--%>
<%--//            String password = "123456";--%>
<%--//            Connection connection= DriverManager.getConnection(url,user,password );--%>
<%--////            out.println(connection);--%>
<%--////    3：创建命令对象--%>
<%--//            Statement statement=connection.createStatement();--%>
<%--//            4：执行命令对象，返回结果--%>
<%--//    4-1：查询--%>
<%--            String sql="select id,patient_name, age, gender, birthday, diagnosis_result, admission_date, expected_discharge_date, ward_number, bed_number from bingfang;";--%>
<%--            ResultSet resultSet = dbUtil.queryBySQL(sql);// 执行SQL查询，并获取结果集--%>
<%--            while (resultSet.next()){%>--%>
<%--        <tr>--%>
<%--            <td><%=resultSet.getInt("id")%></td>--%>
<%--            <td><%=resultSet.getString("patient_name")%> </td>--%>
<%--            <td><%=resultSet.getInt("age")%></td>--%>
<%--            <td><%=resultSet.getString("gender")%></td>--%>
<%--            <td><%=resultSet.getString("birthday")%></td>--%>
<%--            <td><%=resultSet.getString("diagnosis_result")%></td>--%>
<%--            <td><%=resultSet.getString("admission_date")%></td>--%>
<%--            <td><%=resultSet.getString("expected_discharge_date")%></td>--%>
<%--            <td><%=resultSet.getString("ward_number")%></td>--%>
<%--            <td><%=resultSet.getString("bed_number")%></td>--%>
<%--            <td> <a href="BingFangDelete.jsp?id=<%=resultSet.getInt("id")%>" onclick="return confirm('是否删除这条记录')">删除</a>--%>
<%--                <a href="BingFangDelete.jsp">编辑</a></td>--%>
<%--        </tr>--%>
<%--        <%}--%>
<%--            resultSet.close();--%>
<%--//            statement.close();--%>
<%--//            connection.close();--%>
<%--        %>--%>
<%--        </tbody>--%>
<%--    </table>--%>
<%--</div>--%>
<%--</body>--%>
<%--</html>--%>

<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.gzsz.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>病房表格</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <style>
        /* 自定义动画 */
        .animate-fade-in {
            animation: fadeIn 0.3s ease-out;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        /* 按钮悬停时的阴影效果 */
        .btn-hover-shadow:hover {
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }

        /* 表格行悬停效果 */
        .table-row-hover:hover {
            background-color: #f3f4f6;
        }
    </style>
</head>

<body class="bg-gray-100 font-sans">
<div class="container mx-auto py-8 px-4">
    <div class="flex justify-between items-center mb-4">
        <form action="BingFang.jsp" method="get" class="flex space-x-2">
            <input type="text" name="search" placeholder="输入患者信息查询"
                   class="border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
            <input type="submit" value="查询"
                   class="bg-blue-500 text-white rounded-md px-4 py-2 hover:bg-blue-600 transition-colors btn-hover-shadow">
        </form>
        <div class="flex items-center">
            <a href="bingfangguanli.jsp"
               class="bg-green-500 text-white rounded-md px-4 py-2 hover:bg-green-600 transition-colors btn-hover-shadow">
                添加信息
            </a>
            <!-- 添加返回按钮 -->
            <a href="#" id="backBtn"
               class="ml-2 text-gray-500 hover:text-gray-700 transition-colors">
                <i class="fa-solid fa-angle-left"></i> 返回
            </a>
        </div>
    </div>

    <div class="bg-white rounded-md shadow-md overflow-x-auto">
        <table class="table-auto w-full">
            <thead class="bg-gray-50">
            <tr>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">编号</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">患者姓名</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">年龄</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">性别</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">出生日期</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">诊断结果</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">住院日期</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">预计出院日期</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">病房号</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">病床号</th>
                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">数据操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                DBUtil dbUtil = new DBUtil();
                String search = request.getParameter("search");
                String sql;
                PreparedStatement pstmt = null;
                ResultSet resultSet = null;
                try {
                    if (search != null && !search.isEmpty()) {
                        // 精确匹配病房号和病床号，同时保留患者姓名的模糊匹配
                        sql = "select id,patient_name, age, gender, birthday, diagnosis_result, admission_date, expected_discharge_date, ward_number, bed_number from bingfang where  patient_name like ? or ward_number = ? or bed_number = ?";
                        pstmt = dbUtil.getConnection().prepareStatement(sql);
                        pstmt.setString(1, "%" + search + "%");
                        pstmt.setString(2, search);
                        pstmt.setString(3, search);
                    } else {
                        sql = "select id,patient_name, age, gender, birthday, diagnosis_result, admission_date, expected_discharge_date, ward_number, bed_number from bingfang";
                        pstmt = dbUtil.getConnection().prepareStatement(sql);
                    }
                    resultSet = pstmt.executeQuery();
                    while (resultSet.next()) {
            %>
            <tr class="border-b table-row-hover">
                <td class="px-6 py-4"><%=resultSet.getInt("id")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("patient_name")%></td>
                <td class="px-6 py-4"><%=resultSet.getInt("age")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("gender")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("birthday")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("diagnosis_result")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("admission_date")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("expected_discharge_date")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("ward_number")%></td>
                <td class="px-6 py-4"><%=resultSet.getString("bed_number")%></td>
                <td class="px-6 py-4">
                    <a href="BingFangDelete.jsp?id=<%=resultSet.getInt("id")%>"
                       onclick="return confirm('是否删除这条记录')"
                       class="text-red-500 hover:text-red-600 transition-colors">
                        <i class="fa-solid fa-trash"></i> 删除
                    </a>
                    <a href="BingFangDelete.jsp"
                       class="text-yellow-500 hover:text-yellow-600 transition-colors ml-2">
                        <i class="fa-solid fa-pen-to-square"></i> 编辑
                    </a>
                </td>
            </tr>
            <%
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (resultSet != null) resultSet.close();
                        if (pstmt != null) pstmt.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            %>
            </tbody>
        </table>
    </div>
</div>

<script>
    // 获取返回按钮
    var backBtn = document.getElementById("backBtn");

    // 当用户点击返回按钮时，清空查询参数并重新加载页面
    backBtn.onclick = function (event) {
        event.preventDefault();
        window.location.href = "BingFang.jsp";
    };
</script>
</body>

</html>